﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Eis51.CampanyCMS.Business.Bus;
using Eis51.CampanyCMS.Model;
using Eis51.CampanyCMS.Model.Bus;
using Eis51.Web.Admin;

namespace Eis51.CampanyCMS.WebUI.Admin.Order
{
    public partial class MyPaymentList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ShowData();
            }
        }

        private void ShowData()
        {
            DataTable dt = MypaymentBLL.GetInstance().GetPayMent(AppContext.CurrentAdministrator.Createby ) ;
            dgNews.Data = dt;
            dgNews.DataBind();
        }

        protected void btnAdd_Click(object sender, System.EventArgs e)
        {
            Response.Redirect("MyPaymentPage.aspx");
        }

        protected void dgNews_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Delete":
                    Mypayment p = MypaymentBLL.GetInstance().Get(new Mypayment.Key(int.Parse(e.Item.Cells[0].Text)));
                    MypaymentBLL.GetInstance().Delete(p);
                    ShowData();
                    break;
                case "Modify":
                    string url = "MyPaymentPage.aspx?seqno={0}";
                    url = string.Format(url, e.Item.Cells[0].Text);
                    Response.Redirect(url);
                    break;
                default:
                    break;
            }
        }

        protected void dgNews_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem ||
                e.Item.ItemType == ListItemType.Item)
            {
                LinkButton btnDelete = e.Item.FindControl("btnDelete") as LinkButton;
                LinkButton btnModify = e.Item.FindControl("btnModify") as LinkButton;
                if (btnDelete != null)
                {
                    btnDelete.Attributes.Add("onclick", "javascript:return confirm('是否删除?');");
                }
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            ShowData();
        }
    }
}
